package com.hgkj.cloud.base.scheme.table;

import com.hgkj.cloud.base.scheme.ClsAnswerRequest;
import com.hgkj.cloud.base.scheme.ClsAnswerResult;
import com.hgkj.cloud.base.scheme.ClsScore;

import java.util.Map;

/**
 * 131: 公安民警应激生活事件调查表（Shirritant），共28题27+1，1个因子，2个选项
 */
public class Table131 implements TableCalculate{
    String code = "Shirritant";

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public ClsAnswerResult calc(ClsAnswerRequest answer) {
        return GetShirritantFactorScore(answer);
    }

    @Override
    public String[] report(Map map) {
        return new String[0];
    }

    private static ClsAnswerResult GetShirritantFactorScore(ClsAnswerRequest answer) {
        // 总分
        ClsAnswerResult result = new ClsAnswerResult();
        result.setMessage("");
        result.setType(answer.getType());
        result.setUuid(answer.getUuid());
        try {
            // 1正确题数
            int MAX_NUM = 28;

            int intI;
            // 转换回原来格式
            String strTemp = answer.getAnswer().replaceAll("\\|@", "\\|0@@");
            // 临时赋值，JAVA默认切割时为空就不增加数组长度
            String[] strAnswer_c_Temp = strTemp.split(g_sChar);
            String[] strAnswer_c = { "", "" };
            for (intI = 0; intI < strAnswer_c_Temp.length; intI++) {
                strAnswer_c[intI] = strAnswer_c_Temp[intI].trim();
            }

            String[] strClientAnswerA = strAnswer_c[0].toString().split(g_nChar);

            if (strClientAnswerA.length != MAX_NUM) {
                result.setMessage("答案数量不符！");
                return result;
            }

            int i;

            // 得分组
            int[] intScoreA = {};

            float vFactor = 0;

            float sngAge = answer.getAge();

            if (sngAge < 31) {
                int[] arrScore = { 55, 30, 34, 51, 31, 28, 32, 56, 60, 23, 42, 37, 25, 30, 41, 30, 26, 23, 20, 16, 42,
                        25, 21, 16, 22, 25, 36 };
                intScoreA = arrScore;
            } else if (31 <= sngAge && sngAge < 41) {
                int[] arrScore = { 45, 34, 44, 52, 40, 38, 38, 53, 52, 25, 43, 37, 26, 34, 39, 46, 25, 30, 21, 20, 41,
                        27, 27, 20, 22, 31, 38 };
                intScoreA = arrScore;
            } else {
                int[] arrScore = { 44, 29, 44, 47, 42, 42, 40, 48, 44, 29, 46, 35, 30, 29, 41, 49, 23, 32, 22, 19, 47,
                        26, 23, 21, 19, 35, 36 };
                intScoreA = arrScore;
            }

            for (i = 0; i < strClientAnswerA.length; i++) {
                if (Integer.valueOf(strClientAnswerA[i]) == 1) {
                    vFactor += intScoreA[i];
                }
            }

            int[] intValueA = { 490, 660 };
            String vDoctorIdea = "Shirritant.1.3";
            for (i = 0; i < intValueA.length; i++) {
                if (vFactor < intValueA[i]) {
                    vDoctorIdea = "Shirritant.1." + String.valueOf(i + 1);
                    break;
                }
            }

            ClsScore.Shirritant shirritant = new ClsScore.Shirritant();

            shirritant.setTotal_o(vFactor);
            shirritant.setTotal_d(vDoctorIdea);

            result.setObject(shirritant);
            return result;
        } catch (ArithmeticException e) {
            result.setMessage(e.toString());
            return result;
        }
    }


}
